﻿using HomeCareLibrary.Core.Dtos;
using HomeCareLibrary.DataAccess;
using HomeCareLibrary.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HomeCareLibrary.AppService.Mappers;
using HomeCareLibrary.Core.DataContracts;

namespace HomeCareLibrary.AppService
{
    public class TipsAppService : AppServiceBase
    {
        public List<CTTipDetailDto> GetTipDetail(string tipCode)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var tipRepository = new Repository<CTTipDetail>(unitOfWork);
                var queryParameter = string.Format("@tip_code={0}", tipCode);
                return tipRepository.ExecuteFuntion("[sp_gettipDetail]", queryParameter).ToDTOs();
            }
        }

        public List<CTTipDetailDto> GetTips(string dwellPriorityKLLoc, string featureString, string psGoalString, string turnOffs, string startMonth, string startYear, string requestedMonth, string requestedYear)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var repository = new Repository<CTTipDetail>(unitOfWork);
                var queryParameter = string.Format("@dwell_priority_kl_loc='{0}', @feature_string='{1}', @ps_goal_string='{2}' ,@turn_offs='{3}', @startmonth={4}, @startyear={5}, @requestedmonth={6}, @requestedyear={7}",dwellPriorityKLLoc, featureString, psGoalString, turnOffs, startMonth, startYear, requestedMonth, requestedYear);
                return repository.ExecuteFuntion("[sp_Tips]",queryParameter).ToDTOs();
            }
        }

        public List<CTTipDto> GetTipsList(TasksRequest request)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var repository = new Repository<CTTip>(unitOfWork);
                var queryParameter = string.Format("@paramUserId={0}, @paramHomeNumber={1}, @paramRequestedMonth={2}, @paramRequestedYear={3}", request.UserId, request.HomeNumber, request.Month, request.Year);
                return repository.ExecuteFuntion("[sp_Tips_List]", queryParameter).ToDTOs();
            }
        }
    }
}
